﻿@using thousandclear.Data;
@model List<T_Message_Board>
@{
    ViewBag.Title = "留言板管理";
    Layout = "~/Areas/Admin/Views/Shared/_Admin.cshtml";
}

<div id="app">
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">后台管理</strong> / <small>@ViewBag.Title</small></div>
    </div>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>昵称：</label>
                <input type="text" class="am-input-sm" v-model="name" />
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
                <label>状态：</label>
                <select v-model="status">
                    <option value="">全部</option>
                    <option value="3">已回复</option>
                    <option value="2">已删除</option>
                    <option value="1">未回复</option>
                </select>
            </div>
        </div>

        <div class="am-g">
            <div class="am-u-sm-12">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>昵称</th>
                            <th>留言</th>
                            <th>图片</th>
                            <th>回复</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>

                        @foreach (T_Message_Board item in Model)
                        {
                            <tr>
                                <td>@item.TMBID.ToString()</td>
                                <td>@item.CreatedBy</td>
                                <td>@item.tmbDesc</td>
                                
                                <td>
                                    @if (item.tmbImg1 != "")
                                    {
                                        <img src="@ViewBag.URL@item.tmbImg1" style="width: 50px;height: 50px;" />
                                    }
                                    @if (item.tmbImg2 != "")
                                    { 
                                        <img src="@ViewBag.URL@item.tmbImg2" style="width: 50px;height: 50px;" /> 
                                    }
                                    @if (item.tmbImg3 != "")
                                    {  
                                        <img src="@ViewBag.URL@item.tmbImg3" style="width: 50px;height: 50px;" />
                                    }
                                    @if (item.tmbImg4 != "")
                                    {  
                                        <img src="@ViewBag.URL@item.tmbImg4" style="width: 50px;height: 50px;" />
                                    }
                                    @if (item.tmbImg5 != "")
                                    {  
                                        <img src="@ViewBag.URL@item.tmbImg5" style="width: 50px;height: 50px;" />
                                    }
                                    @if (item.tmbImg6 != "")
                                    { 
                                        <img src="@ViewBag.URL@item.tmbImg6" style="width: 50px;height: 50px;" /> 
                                    }
                                    @if (item.tmbImg7 != "")
                                    { 
                                        <img src="@ViewBag.URL@item.tmbImg7" style="width: 50px;height: 50px;" /> 
                                    }
                                    @if (item.tmbImg8 != "")
                                    {
                                        <img src="@ViewBag.URL@item.tmbImg8" style="width: 50px;height: 50px;" />
                                    }
                                    @if (item.tmbImg9 != "")
                                    {
                                        <img src="@ViewBag.URL@item.tmbImg9" style="width: 50px;height: 50px;" />
                                    }
                                </td>
                                <td>@item.tmbBack</td>
                                <td>
                                    @if (ViewBag.level != "2")
                                    {
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a v-on:click="giveMessage(@item.TMBID)"data-am-modal="{target: '#doc-modal-3', closeViaDimmer: 0, width: 800, height: 600}" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span>回复</a>
                                            </div>
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a v-on:click="remove(@item.TMBID)" class="am-btn am-btn-primary am-btn-xs am-hide-sm-only"><span class="am-icon-edit"></span> 删除</a>
                                            </div>
                                        </div>
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                <div class="am-cf">
                    &nbsp;&nbsp;共 {{totalCount}} 条记录, 每页 {{pageCount}} 条记录
                    <div class="am-fr">
                        <ul class="am-pagination">
                            <li style="width: 60px">
                                <input class="am-form-field" style="text-align:center" type="text" v-model="gotoPage">

                            </li>
                            <li><a href="#" v-on:click="goto">GoTo &raquo;</a></li>
                            <li><a href="#" v-on:click="prev">&laquo; Prev</a></li>
                            <li><span>{{currentPage}}/{{totalPage}}</span></li>
                            <li><a href="#" v-on:click="next">Next &raquo;</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-3">
            <div class="am-modal-dialog" style="overflow-y:auto;">
                <div class="am-modal-hd">
                    回复留言板
                    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
                </div>
                <div class="am-modal-bd">
                    <div class="am-g">
                        <div class="am-u-sm-12">
                            <textarea v-model="backmessageDesc" style="width: 80%;height: 200px;">
                            </textarea>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12">
                        <button class="am-btn am-btn-primary" v-on:click="backmessage" >回复</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script>
        $('.admin-sidebar-wall').addClass('current');
        var model = new Vue({
            el: '#app',
            data: {
                name:'',
                id:'',
                status:'',
                totalCount: @ViewBag.TotalCount,
                currentPage: @ViewBag.CurrentPage,
                pageCount: @ViewBag.PageCount,
                gotoPage: @ViewBag.CurrentPage,
                totalPage: @ViewBag.TotalPage,
                backmessageDesc:'',
            },
            methods: {
                prev: function() {
                    var self = this;
                    if (self.currentPage <= 1)
                        return;

                    self.currentPage -= 1;
                    self.load();
                },
                next: function() {
                    var self = this;

                    if (self.currentPage >= self.totalPage)
                        return;

                    self.currentPage += 1;

                    self.load();
                },
                goto: function() {
                    var self = this;
                    self.currentPage = self.gotoPage;
                    self.load();
                },
                search: function() {
                    var self = this;
                    self.currentPage = 1;
                    self.load();
                },
                load: function() {
                    var self = this;
                    window.location.href = "../admin/Message?page=" + self.currentPage + "&count=" + self.pageCount+"&name=" + self.name+"&status=" + self.status;
                },
                giveMessage: function(idx){
                    var self= this;
                    self.id=idx;
                },
                remove: function (idx) {
                    var self = this;
                    if (confirm('确认要删除吗?')) {
                        $.ajax({
                            type: "get",
                            url: "../admin/Message/remove/"+idx,
                            contentType: "application/json",
                            success: function (data) {
                                alert("删除成功");
                                window.location.reload();
                            }

                        })


                    }
                    else {
                        return;
                    }


                },
                backmessage: function () {
                    var self = this;
                    var data={"TMBID": self.id, "BackDetail":self.backmessageDesc };
                    if (confirm('确认要回复吗?')) {
                        $.ajax({
                            type: "get",
                            url: "../admin/Message/back",
                            data: data,
                            contentType: "application/json",
                            success: function (data) {
                                alert("回复成功");
                                window.location.reload();
                            }

                        })


                    }
                    else {
                        return;
                    }


                }

            }
        });

        //$('.admin-sidebar-Good').addClass('current');


    </script>
}

